<?php

/**
 * @author    zhe.wang
 * @desc      所有方法需为私有
 *
 */
class Configure
{
    private static $count = 0;

    private function __construct()
    {
    }

    /**
     * 初始化方法
     * @throws \ReflectionException
     */
    public static function init()
    {
        if (self::$count) {
            return;
        }

        $instance = new self();
        $ref      = new \ReflectionClass($instance);
        if (!empty($ref->getMethods())) {
            foreach ($ref->getMethods() as $v) {
                $classMethodName = $v->name;
                if ($classMethodName && $classMethodName !== __FUNCTION__ && strpos($classMethodName, '__') !== false) {
                    $instance->$classMethodName();
                }
            }
        }
        self::$count++;
    }

    // 加载助手类
    private static function __loadHelper()
    {
        foreach (glob(__DIR__ . '/../app/Libs/Helpers/*.php') as $file) {
            if (is_file($file)) {
                include_once $file;
            }
        }

        return true;
    }

    // 定义常量
    private static function __setDefineVariables()
    {
        $envs = self::__loadDefaultEnv();
        if (!empty($envs)) {
            foreach ($envs as $k => $v) {
                $_SERVER[$k] = $v;
            }
        }
        return true;
    }

    // 读取默认配置文件
    private static function __loadDefaultEnv()
    {
        $default_env = __DIR__ . '/../.env';
        if (is_file($default_env)) {
            return parse_ini_file($default_env);
        }

        return [];
    }
    
    //改变storage和env路径
    private static function __setMyPath()
    {
        define('MY_LOG_PATH', '/data/app/logs/lumen_demo');
        define('MY_ENV_PATH', '/data/app/config/lumen_demo/env');
        define('MY_ENV_FILE_NAME', 'ini');
    }
}

// 执行
Configure::init();
